package org.erepublik.company.controllers;

import javax.servlet.http.HttpServletRequest;

import org.erepublik.company.Location;
import org.erepublik.company.charts.ChartFactory;
import org.erepublik.company.charts.CountryJSONDataCollector;
import org.erepublik.company.utils.Utils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/currencyChart.html")
public class CurrencyChartController extends AbstractController {
    
    @RequestMapping(method = RequestMethod.GET)
    public String showForm(HttpServletRequest request, ModelMap model) {
        fillModelMap(model);
        Location country = null;
        if (request.getParameter("country") != null && !request.getParameter("country").equals("")) {
            country = Utils.getLocationFromString( request.getParameter("country") ) ;
        }
 
        model.addAttribute("weekChart", ChartFactory.getExchangeRateChart2Weeks(
                    (CountryJSONDataCollector) countryDataService.getDataCollctor("currency"), country));

        return "currencyChart";
    }
}
